package com.zxx.ssm.model.convertor;

import com.zxx.ssm.dao.Guoziclass;
import com.zxx.ssm.dao.TeacherStudentClass;
import com.zxx.ssm.dao.TeacherStudentClassLog;
import com.zxx.ssm.model.biz.StuClassCountBiz;
import com.zxx.ssm.model.biz.StuClasstypeGroupBiz;
import com.zxx.ssm.model.biz.TeaClassCountBiz;
import com.zxx.ssm.model.biz.TeaClasstypeGroupBiz;
import com.zxx.ssm.model.form.TeacherStudentClassForm;
import com.zxx.ssm.util.DateUtils;
import com.zxx.ssm.util.StringUtils;

import java.util.ArrayList;
import java.util.List;

public class TeacherStudentClassConvertor {
    public static Guoziclass convToGuozi(TeacherStudentClassForm teacherStudentClassForm){
        Guoziclass guoziclass = new Guoziclass();
        guoziclass.setClasstype(teacherStudentClassForm.getClassType());
        guoziclass.setCoursetype(teacherStudentClassForm.getCourseType());
        guoziclass.setClassday(DateUtils.toDate(teacherStudentClassForm.getStartTime()));
        String classStartTime =  DateUtils.curTimeStr4(teacherStudentClassForm.getStartTime());
        if("01:00".equals(classStartTime))
            guoziclass.setTimeblockid(1);
        else if("02:00".equals(classStartTime))
            guoziclass.setTimeblockid(2);
        else if("03:00".equals(classStartTime))
            guoziclass.setTimeblockid(3);
        else if("04:00".equals(classStartTime))
            guoziclass.setTimeblockid(4);
        else
            guoziclass.setTimeblockid(5);
        return guoziclass;
    }

    public static List<TeacherStudentClass> convToTeaStuCla(TeacherStudentClassForm teacherStudentClassForm, Integer guoziClassId) {
        String[] stuIds = teacherStudentClassForm.getStudentList().split(",");
        List<TeacherStudentClass> teacherStudentClassList = new ArrayList<TeacherStudentClass>();
        for (int i=0;i<stuIds.length;i++){
            TeacherStudentClass teacherStudentClass = new TeacherStudentClass();
            teacherStudentClass.setClassId(guoziClassId);
            teacherStudentClass.setTeacherid(teacherStudentClassForm.getTeacherid());
            teacherStudentClass.setStudentid(StringUtils.toInt(stuIds[i]));
            teacherStudentClassList.add(teacherStudentClass);
        }
        return teacherStudentClassList;

    }

    public static List<TeacherStudentClassLog> convToTeaStuClaLog(TeacherStudentClassForm teacherStudentClassForm, Guoziclass guoziclass) {
        String[] stuIds = teacherStudentClassForm.getStudentList().split(",");
        List<TeacherStudentClassLog> teacherStudentClassLogs = new ArrayList<TeacherStudentClassLog>();
        for (int i=0;i<stuIds.length;i++){
            TeacherStudentClassLog teacherStudentClassLog = new TeacherStudentClassLog();
            teacherStudentClassLog.setClassday(guoziclass.getClassday());
            teacherStudentClassLog.setClasstype(guoziclass.getClasstype());
            teacherStudentClassLog.setCoursetype(guoziclass.getCoursetype());
            teacherStudentClassLog.setTimeblockid(guoziclass.getTimeblockid());
            teacherStudentClassLog.setTeacherid(teacherStudentClassForm.getTeacherid());
            teacherStudentClassLog.setOperator(1);
            teacherStudentClassLog.setState(1);
            teacherStudentClassLog.setUserid(StringUtils.toInt(stuIds[i]));
            teacherStudentClassLogs.add(teacherStudentClassLog);
        }
        return teacherStudentClassLogs;
    }

    public static TeaClassCountBiz convToTeaClassCountBiz(List<TeaClasstypeGroupBiz> teaStuClassBizList) {
        TeaClassCountBiz teaClassCountBiz = new TeaClassCountBiz();
        teaClassCountBiz.setOralNum(0);
        teaClassCountBiz.setListeningNum(0);
        teaClassCountBiz.setReadingNum(0);
        teaClassCountBiz.setWritingNum(0);
        for(int i=0;i<teaStuClassBizList.size();i++){
            TeaClasstypeGroupBiz teaClasstypeGroupBiz = teaStuClassBizList.get(i);
            String classtype= teaClasstypeGroupBiz.getClasstype();
            Integer num = teaClasstypeGroupBiz.getNum();
            if(classtype.equals("口语"))
                teaClassCountBiz.setOralNum(num);
            else if(classtype.equals("听力"))
                teaClassCountBiz.setListeningNum(num);
            else if(classtype.equals("阅读"))
                teaClassCountBiz.setReadingNum(num);
            else
                teaClassCountBiz.setWritingNum(num);
        }
        return teaClassCountBiz;
    }

    public static StuClassCountBiz convToStuClassCountBiz(List<StuClasstypeGroupBiz> stuClasstypeGroupBizList) {
        StuClassCountBiz stuClassCountBiz = new StuClassCountBiz();
        stuClassCountBiz.setOralNum(0);
        stuClassCountBiz.setListeningNum(0);
        stuClassCountBiz.setReadingNum(0);
        stuClassCountBiz.setWritingNum(0);
        for(int i=0;i<stuClasstypeGroupBizList.size();i++){
            StuClasstypeGroupBiz stuClasstypeGroupBiz = stuClasstypeGroupBizList.get(i);
            String classtype= stuClasstypeGroupBiz.getClasstype();
            Integer num = stuClasstypeGroupBiz.getNum();
            if(classtype.equals("口语"))
                stuClassCountBiz.setOralNum(num);
            else if(classtype.equals("听力"))
                stuClassCountBiz.setListeningNum(num);
            else if(classtype.equals("阅读"))
                stuClassCountBiz.setReadingNum(num);
            else
                stuClassCountBiz.setWritingNum(num);
        }
        return stuClassCountBiz;
    }
}
